

<script>
	import {mapState, mapMutations} from 'vuex'
	// 引入插件
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
	import wybPopup from '@/components/wyb-popup/wyb-popup.vue'
	import cmdProgress from "@/components/cmd-progress/cmd-progress.vue"
	import audio2 from "@/components/wangding-audioQuickPlay/index.vue"
	import xiexImage from '@/components/xiex-image/xiex-image.vue'
	
	const iac = uni.createInnerAudioContext()
	
	export default {
		onLaunch: function() {
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show')
			iac.onEnded(()=>{
				// this.nowSong.playState = true
				// console.log(this.$store.getters.nextPlayData)
				if(this.$store.getters.nextPlayData.flag)iac.play()
				else{
					//播放列表为空，自动进入单曲循环,这里可以通过/simi/song?id=347230获取相似音乐的
					if(this.$store.getters.nextPlayData.list.length==0)return iac.play()
					let nextSong = this.$store.getters.nextPlayData.list[0]
					uni.request({
						url: "http://localhost:3000/song/url?id=" + nextSong.id,
						success: (res) => {
							console.log(res.data)
							if(!res.data.data[0].url)return uni.showToast({
								title: '暂时比较穷',
								icon: 'none'
							})
							nextSong.url =res.data.data[0].url
							iac.src = res.data.data[0].url
							nextSong.playState = true
							this.$store.commit('songChange', nextSong)
							iac.play()
							this.$store.commit('nextPlayShift')
						}
					})		
				}
			})
		},
		onHide: function() {
			console.log('App Hide')
		},
		components: {
		    wybPopup,
			uniNavBar,
			cmdProgress,
			audio2,
			xiexImage
		},
		mounted: {
			...mapState(['image', 'url', 'playState'])
		},
		methods:{
			...mapMutations(['songChange']),
		},
		globalData:{
			iac:iac
		}
		
	}
</script>

<style  scoped>
	/*每个页面公共css */
	@import url("./static/common.css");
	@import "http://at.alicdn.com/t/font_2064057_2osz9sz0du2.css"
	
</style>